package 每日一题;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class 重复的DNA子串 {

    public List<String> findRepeatedDnaSequences(String s) {
        List<String> list = new ArrayList<>();
        if (s.length()<=10)
            return list;
        HashMap<String, Integer> map = new HashMap<>();
        for (int i = 0; i < s.length()-9; i++) {
            String substring = s.substring(i, i + 10);
            if (!map.containsKey(substring))
                map.put(substring,1);
            else if (!list.contains(substring)){
                list.add(substring);
            }
        }
        return list;
    }
    @Test
    public void test(){
        String s="abcdefg";
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            String substring = s.substring(i, i + 2);
            list.add(substring);
        }
        for (String s1 : list) {
            System.out.println(s1);
        }
    }

}
